﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;
using System.Data;

namespace Besture.UI
{
    public partial class HotelExchangeSet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {
			
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new HotelExchangeDac();
            var model = dac.GetModel(id);
			if(model==null) return;

            txtIntegration.Text = model.Integration.ToString();
			txtIntegrationRMB.Text = model.IntegrationRMB.ToString();
			txtMemberNightNumber.Text = model.MemberNightNumber.ToString();
			txtMemberNightNumberRMB.Text = model.MemberNightNumberRMB.ToString();
			txtSilverMemberNightNumber.Text = model.SilverMemberNightNumber.ToString();
			txtSilverMemberNightNumberRMB.Text = model.SilverMemberNightNumberRMB.ToString();
			txtGoldMemberNightNumber.Text = model.GoldMemberNightNumber.ToString();
			txtGoldMemberNightNumberRMB.Text = model.GoldMemberNightNumberRMB.ToString();

			
        }
        #endregion

        #region 保存

        protected void BtnSubmitClick(object sender, EventArgs eventArgs)
        {
            var dac = new HotelExchangeDac();
            HotelExchangeModel model=null;
            var baseDac = new BaseDac<HotelExchangeModel>();
            //添加
            if (!EditPage)
            {
                model = new HotelExchangeModel();
                model.Integration = Convert.ToInt32(txtIntegration.Text.Trim());
				model.IntegrationRMB = Convert.ToInt32(txtIntegrationRMB.Text.Trim());
				model.MemberNightNumber = Convert.ToInt32(txtMemberNightNumber.Text.Trim());
				model.MemberNightNumberRMB = Convert.ToInt32(txtMemberNightNumberRMB.Text.Trim());
				model.SilverMemberNightNumber = Convert.ToInt32(txtSilverMemberNightNumber.Text.Trim());
				model.SilverMemberNightNumberRMB = Convert.ToInt32(txtSilverMemberNightNumberRMB.Text.Trim());
				model.GoldMemberNightNumber = Convert.ToInt32(txtGoldMemberNightNumber.Text.Trim());
                model.GoldMemberNightNumberRMB = Convert.ToInt32(txtGoldMemberNightNumberRMB.Text.Trim());
                //加载添加基本数据
                baseDac.LoadAddBaseModel(model);
                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(ID);
                if (model != null)
                {
                    model.Integration = Convert.ToInt32(txtIntegration.Text.Trim());
                    model.IntegrationRMB = Convert.ToInt32(txtIntegrationRMB.Text.Trim());
                    model.MemberNightNumber = Convert.ToInt32(txtMemberNightNumber.Text.Trim());
                    model.MemberNightNumberRMB = Convert.ToInt32(txtMemberNightNumberRMB.Text.Trim());
                    model.SilverMemberNightNumber = Convert.ToInt32(txtSilverMemberNightNumber.Text.Trim());
                    model.SilverMemberNightNumberRMB = Convert.ToInt32(txtSilverMemberNightNumberRMB.Text.Trim());
                    model.GoldMemberNightNumber = Convert.ToInt32(txtGoldMemberNightNumber.Text.Trim());
                    model.GoldMemberNightNumberRMB = Convert.ToInt32(txtGoldMemberNightNumberRMB.Text.Trim());
                    //加载修改基本数据
                    baseDac.LoadUpdateBaseModel(model);
                    dac.Update(model);
                }
            }

            FunHelper.Alert("保存成功", Request.Url.ToString());
        }
        #endregion
    }
}